package com.hspedu.homework.homework01;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/24
 * @time 18:27
 */
public class Homework01 {
    public static void main(String[] args) {
        Person[] people = new Person[3];
        Person jack = new Person("jack", 19, "teacher");
        Person bob = new Person("bob", 27, "worker");
        Person hsp = new Person("hsp", 14, "student");
        people[0] = jack;
        people[1] = bob;
        people[2] = hsp;
        Homework01 homework01 = new Homework01();
        homework01.bubbleSort(people);

    }

    public void bubbleSort(Person[] people) {
        for (int i = 1; i <= people.length - 1; i++) {
            for (int j = 1; j <= people.length - i ; j++) {
                Person temp = null;
                if (people[j-1].getAge() > people[j].getAge()){
                    temp = people[j-1];
                    people[j-1] = people[j];
                    people[j] = temp;
                }
            }
        }

        for (int i = 0; i < people.length; i++) {
            System.out.println(people[i]);
        }
    }
}

class Person {
    private String name;
    private int age;
    private String job;

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }

    protected String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }
}
